/**
 * Created by jianglinjie on Wed Oct 11 2017
 */
'use strict';
import ConfigService from '../config';
import RegisterService from '../register';
import CaptchaService from '../captcha';
import * as CaptchaBusiness from '../../constants/CaptchaBusiness';
import Random from 'random-js';
import { md5 } from '../../utils/StringUtils';

test('REGISTER_WITH_ACCOUNT', async () => {
  console.log('apibasehost %s', ConfigService.apiBaseHost);

  let userName = 'T' + (new Random()).string(10);
  let password = '123456';
  let userInfo = await RegisterService.registerWithUserName(userName, password);
  expect(userInfo.uid).toBeTruthy();
  expect(userInfo.userName).toMatch(userName);
  expect(userInfo.encryptPwd).toMatch(md5(password));
});

test('REGISTER_WITH_PHONE', async () => {
  console.log('apibasehost %s', ConfigService.apiBaseHost);
  let phone = '1' + (new Random()).string(10, '0123456789');
  let password = '123456'; 
  let captchaResult = await CaptchaService.request({
    phone: phone,
    business: CaptchaBusiness.REGISTER
  });

  let userInfo = await RegisterService.registerWithPhone(phone, password, captchaResult.captcha);
  expect(userInfo.uid).toBeTruthy();
  expect(userInfo.phone).toMatch(phone);
  expect(userInfo.encryptPwd).toMatch(md5(password));
});